package cn.yunhe.services.impl;

import cn.yunhe.services.IXsTreamServices;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/6/9.
 */
@Service("xsTreamServices")
public class XsTreamServices implements IXsTreamServices{
    @Override
    public String objectToXml(Object obj) {
        XStream xStream=new XStream();
        xStream.processAnnotations(obj.getClass());
        return xStream.toXML(obj);
    }
    @Override
    public <T> T xmlToObjext(String xml, Class<T> cla) {
        XStream xStream=new XStream(new DomDriver());
        xStream.processAnnotations(cla);
        return (T)xStream.fromXML(xml);
    }
}
